]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
status/network: Use D-Bus to launch Settings panels
authorFlorian Müllner <fmuellner@gnome.org>
Fri, 31 Jul 2020 18:40:36 +0000 (20:40 +0200)
committerGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Mon, 3 Aug 2020 16:17:40 +0000 (16:17 +0000)
For more obscure network configurations, we need to launch the
corresponding Settings panel with additional parameters, so we
cannot simply launch the .desktop file.

However we can do better than spawning a command line: Control center
exposes an application action we can use instead, so the process is
launched with the appropriate activation environment and startup
notification support.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1385

js/ui/status/network.js

index 642e1a104d8a79fe58d7e47824b73442762e730e..3d4acd5b08978c465969017794274a27b389fe03 100644 (file)
@@ -15,6 +15,7 @@ const Util = imports.misc.util;
 
 const { loadInterfaceXML } = imports.misc.fileUtils;
 
+Gio._promisify(Gio.DBusConnection.prototype, 'call', 'call_finish');
 Gio._promisify(NM.Client, 'new_async', 'new_finish');
 Gio._promisify(NM.Client.prototype,
     'check_connectivity_async', 'check_connectivity_finish');
@@ -82,6 +83,30 @@ function ensureActiveConnectionProps(active) {
     }
 }
 
+function launchSettingsPanel(panel, ...args) {
+    const param = new GLib.Variant('(sav)',
+        [panel, args.map(s => new GLib.Variant('s', s))]);
+    const platformData = {
+        'desktop-startup-id': new GLib.Variant('s',
+            '_TIME%s'.format(global.get_current_time())),
+    };
+    try {
+        Gio.DBus.session.call(
+            'org.gnome.ControlCenter',
+            '/org/gnome/ControlCenter',
+            'org.freedesktop.Application',
+            'ActivateAction',
+            new GLib.Variant('(sava{sv})',
+                ['launch-panel', [param], platformData]),
+            null,
+            Gio.DBusCallFlags.NONE,
+            -1,
+            null);
+    } catch (e) {
+        log('Failed to launch Settings panel: %s'.format(e.message));
+    }
+}
+
 var NMConnectionItem = class {
     constructor(section, connection) {
         this._section = section;
@@ -539,8 +564,7 @@ var NMDeviceModem = class extends NMConnectionDevice {
     }
 
     _autoConnect() {
-        Util.spawn(['gnome-control-center', 'network',
-                    'connect-3g', this._device.get_path()]);
+        launchSettingsPanel('network', 'connect-3g', this._device.get_path());
     }
 
     destroy() {
@@ -931,8 +955,8 @@ class NMWirelessDialog extends ModalDialog.ModalDialog {
                 (accessPoints[0]._secType == NMAccessPointSecurity.WPA_ENT)) {
                 // 802.1x-enabled APs require further configuration, so they're
                 // handled in gnome-control-center
-                Util.spawn(['gnome-control-center', 'wifi', 'connect-8021x-wifi',
-                            this._device.get_path(), accessPoints[0].get_path()]);
+                launchSettingsPanel('wifi', 'connect-8021x-wifi',
+                    this._device.get_path(), accessPoints[0].get_path());
             } else {
                 let connection = new NM.SimpleConnection();
                 this._client.add_and_activate_connection_async(connection, this._device, accessPoints[0].get_path(), null, null);